﻿using NoteBook_Product.Extensions;
using Prism.Events;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Regions;

namespace NoteBook_Product.ViewModels
{
    public class NavigationViewModel : BindableBase, INavigationAware
    {
        private readonly IContainerProvider _containerProvider;   // 容器预览者
        private readonly IEventAggregator _eventAggregator;    // 事件聚合器

        public NavigationViewModel(IContainerProvider containerProvider)
        {
            _containerProvider = containerProvider;
            _eventAggregator = containerProvider.Resolve<IEventAggregator>();   // 从容器中拿到事件聚合器
        }

        public virtual bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public virtual void OnNavigatedFrom(NavigationContext navigationContext)
        {

        }

        public virtual void OnNavigatedTo(NavigationContext navigationContext)
        {

        }

        public void UpdateLoading(bool isOpen)
        {
            _eventAggregator.UpdateLoading(new Events.UpdateModel() { IsOpen = isOpen });
        }
    }
}
